#######################
<#
.SYNOPSIS
Adds a database server to RSDD dbms_lku table.
.DESCRIPTION
The Add-dbms function  adds a database server to RSDD dbms_lku table.
.INPUTS
None
    You cannot pipe objects to Add-dbms 
.OUTPUTS
   None
.EXAMPLE
Add-Dbms -dbmsName 'Z003' -dbmsType 'sqlserver' -ConnectionString 'Server=Z003\SQL2K8;Trusted_connection=yes;database=pubs;Provider=SQLNCLI10;'
This command adds a database server with specified connection string
.EXAMPLE
Add-Dbms -dbmsName 'Z003\SQLEXPRESS' -dbmsType 'sqlserver' -ConnectionString 'Server=Z003\SQLEXPRESS;Trusted_connection=yes;database={0};Provider=SQLNCLI10;'  -EnumDatabases
This command adds database server with specified connection string. Because {0} is specified for database
and -EnumDatabases, RSDD will enumerate all databases when Get-ConnectionString is called
.EXAMPLE
Add-Dbms -dbmsName 'Z003' -dbmsType 'oracle' -ConnectionString 'Provider=OraOLEDB.Oracle;Data Source=XE;User Id=RSDD_USER;Password=RSDD_USER;' -Encrypt
This command adds a database server with specified connection string. Because -Encrypt is specified the connection string will be stored
encrypted
.LINK
Add-dbms
#>
function Add-Dbms
{
    [CmdletBinding()]
    param(
    [Parameter(Position=0, Mandatory=$true)] [string]$dbmsName,
    [ValidateSet("oracle", "sqlserver")]
    [Parameter(Position=1, Mandatory=$true)] [string]$dbmsType,
    [Parameter(Position=2, Mandatory=$true)] [string]$ConnectionString,
    [Parameter(Position=3, Mandatory=$false)] [switch]$Encrypt,
    [Parameter(Position=4, Mandatory=$false)] [switch]$Enable=$true,
    [Parameter(Position=5, Mandatory=$false)] [switch]$EnumDatabases
    )

    if ($encrypt)
    { $ConnectionString = Write-EncryptedString -InputString $ConnectionString -Password $Script:Password }

$sql = "INSERT dbo.dbms_lku VALUES('{0}','{1}','{2}',{3},{4},{5})" -f $dbmsName,$dbmsType,$connectionString,[byte]$($Encrypt.IsPresent),[byte]$($Enable.IsPresent),[byte]$($EnumDatabases.IsPresent)

    try { Get-OLEDBData -ConnectionString $Script:OleDbConnString -sql $sql }
    catch {
      $ex = $_.Exception
      Write-LogMessage -Source 'Add-Dbms' -Message "$ex.Message"
      Write-Error "Add-Dbms $ex.Message"
      continue
    }

} #Add-Dbms

